//
//  TransicationDetailCell.m
//  PigMarket
//
//  Created by mac on 2019/5/27.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "TransicationDetailCell.h"

@interface TransicationDetailCell ()
/**
 title
 */
@property (nonatomic , strong) UILabel *titleLab;
/**
 time
 */
@property (nonatomic , strong) UILabel *timeLab;
/**
 money
 */
@property (nonatomic , strong) UILabel *moneyLab;
@end
@implementation TransicationDetailCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *identifierID = @"identifierID";
    TransicationDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierID];
    if (cell == nil) {
        cell = [[TransicationDetailCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifierID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}
#pragma mark - init method
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self.contentView addSubview:self.moneyLab];
    [self.contentView addSubview:self.titleLab];
    [self.contentView addSubview:self.timeLab];
}

- (void)initLayout {
    // 布局子控件
    [self.moneyLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.height.mas_equalTo(20);
        make.right.mas_equalTo(-15);
    }];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(15);
        make.height.mas_equalTo(20);
        make.right.mas_equalTo(self.moneyLab.mas_left).offset(10);
    }];
    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLab.mas_left);
        make.top.mas_equalTo(self.titleLab.mas_bottom).offset(5);
        make.height.mas_equalTo(20);
    }];
}

#pragma mark - getter and setter
- (void)setModel:(TransicationDetail *)model {
    _model = model;
    self.titleLab.text = [NSString stringWithFormat:@"%@:%@",model.remark,model.balanceNum];
    self.timeLab.text = [NSString stringWithFormat:@"%@",model.createTime];
    if ([model.modifyType intValue] == 1) {//进账
        self.moneyLab.text = [NSString stringWithFormat:@"+%@元",model.money];
        self.moneyLab.textColor = [UIColor primaryColor];
    } else if ([model.modifyType intValue] == 2) {//出账
        self.moneyLab.text = [NSString stringWithFormat:@"-%@元",model.money];
        self.moneyLab.textColor = [UIColor textBlackColor];
    }
}
- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.textColor = [UIColor colorWithHexString:@"#999999"];
        _titleLab.font = [UIFont systemFontOfSize:13];
    }
    return _titleLab;
}
- (UILabel *)timeLab {
    if (!_timeLab) {
        _timeLab = [[UILabel alloc] init];
        _timeLab.textColor = [UIColor colorWithHexString:@"#999999"];
        _timeLab.font = [UIFont systemFontOfSize:13];
    }
    return _timeLab;
}
- (UILabel *)moneyLab {
    if (!_moneyLab) {
        _moneyLab = [[UILabel alloc] init];
        _moneyLab.font = [UIFont systemFontOfSize:15];
        _moneyLab.textAlignment = NSTextAlignmentRight;
    }
    return _moneyLab;
}
@end
